from codex import * import time import random import math CENTER = 120 display.fill(BLACK) display.draw_line(CENTER, 0, CENTER, 105, WHITE) display.draw_line(CENTER, 135, CENTER, 239, WHITE) display.draw_line(0, CENTER, 105, CENTER, WHITE) display.draw_line(135, CENTER, 239, CENTER, WHITE) x = CENTER y = CENTER while True: val = accel.read() #read the accelerometer tilt_x = val[0] #gives value of x axis scaled = (tilt_x / 16384) # convert the value to degrees scaled = min(max(scaled, -1),1) #making sure the value was with in range degrees = math.asin(scaled) * 180 / math.pi #math to make sure it is in degrees degrees = int(degrees) tilt_y = val[1] #value for y axis scaledy = (tilt_y / 16384) scaledy = min(max(scaledy, -1),1) degreesy = math.asin(scaledy) * 180 / math.pi degreesy = int(degreesy) display.draw_circle(x, y, 15, BLACK) #erase the orange circle x = CENTER + degrees y = CENTER + degreesy display.draw_circle(x, y, 15, ORANGE)#adjusts x to the degrees calculated if x == CENTER and y == CENTER: display.fill_circle(CENTER, CENTER, 15, GREEN) display.draw_circle(x, y, 15, BLACK) break #display.print(degrees, scale=4) #display.print(val[0]) #this will read only the "x" axis since it is the first place in the () time.sleep(0.2)